package io.github.dgfwork;

import io.github.dgfwork.bean.A;
import io.github.dgfwork.config.MyConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@Slf4j
public class MainTest {

	public static void main(String[] args) {

		ApplicationContext beanFactory = new AnnotationConfigApplicationContext(MyConfig.class);

		// 测试
		/*Object person = beanFactory.getBean("person");
		System.out.println("hello world");
		System.out.println(person);*/

		// 单例注入多例对象
		/*Cat cat1 = beanFactory.getBean(Cat.class);
		Cat cat2 = beanFactory.getBean(Cat.class);
		System.out.println(cat1 == cat2);
		Person person1 = beanFactory.getBean(Person.class);
		Person person2 = beanFactory.getBean(Person.class);
		System.out.println(person2.getCat() == person1.getCat());*/

		// FactoryBean
		//Object bean = beanFactory.getBean("&helloFactory");
		//System.out.println(bean);
		//log.info();

		// 循环依赖
		A a = (A) beanFactory.getBean("a");
		System.out.println("A:" + a);
	}

}
